HAL HSEM initialization and configuration functions migration

The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:

  • Open STM32CubeMX2 HSEM configuration panel.

  • Configure the SW layer HAL.

  • Configure the HSEM advanced features.

  • Configure the HSEM security and privilege features if needed.

  • Configure the NVIC if the application requires the HSEM to be used in IT mode.

  • Generate the code.

HAL HSEM configuration panel

Create a new project with the STM32CubeMX2, then start the initialization and the main configuration

Project configuration panel

HAL HSEM advanced features configuration

Configure the advanced HSEM features.

HSEM advanced feature configuration

HAL HSEM security and privilege features configuration

Configure the HSEM security and privilege features if needed.

HSEM security and privilege feature configuration

NVIC configuration

Configure the NVIC in case of an interrupt.

HSEM NVIC configuration

Generated HSEM initialization and de-initialization sequences

The HSEM initialization and de-initialization sequences are generated in the mx_hsem_init function in mx_hsem.c file under $YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.

STM32CubeMX2 Generated : HSEM initialization and de-initialization sequences

Topic

HAL1 code snippet

HAL2 code snippet

Initialization sequence

/* In HAL1, CubeMX has no dedicated HSEM configuration panel and does
   not generate initialization sequence code. */
system_status_t mx_hsem_init(void)
{

  HAL_RCC_HSEM_EnableClock();
  /* Enable the interruption for semaphore 0 */
  HAL_HSEM_EnableFreeNotificationIT(HAL_HSEM_0);

  /* Enable the interruption for HSEM */
  HAL_CORTEX_NVIC_SetPriority(HSEM_S_IRQn,
                              HAL_CORTEX_NVIC_PREEMP_PRIORITY_0,
                              HAL_CORTEX_NVIC_SUB_PRIORITY_0);

  HAL_CORTEX_NVIC_EnableIRQ(HSEM_S_IRQn);

  return SYSTEM_OK;
}

Deinitialization sequence

/* In HAL1, CubeMX has no dedicated HSEM configuration panel and does
   not generate deinitialization sequence code. */
void mx_hsem_deinit(void)
{

  HAL_HSEM_DisableFreeNotificationIT(HAL_HSEM_0);

  HAL_CORTEX_NVIC_DisableIRQ(HSEM_S_IRQn);

  HAL_RCC_HSEM_Reset();

  HAL_RCC_HSEM_DisableClock();
}

IRQ handle function

void HSEM1_IRQHandler(void)
{
  HAL_HSEM_IRQHandler();
}
void HSEM_S_IRQHandler(void)
{
  HAL_HSEM_IRQHandler();
}